srcdir=@srcdir@
top_builddir=@top_builddir@

CFLAGS=@CFLAGS@
CC=@CC@
OBJCOPY=@OBJCOPY@
LIBC_A=@LIBC_A@
LIBGCC_A=@LIBGCC_A@
DFUWRAP=@DFUWRAP@

INCLUDES="-I@STELLARIS_SDK@"

%.o: ${srcdir}/%.c
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

%.elf:
	$(CC) -Wl,-T -Wl,${srcdir}/link.ld -Wl,--entry -Wl,stellaris_reset -Wl,--gc-sections -o $@ $^ ${LIBC_A} ${LIBGCC_A}

%.bin: %.elf
	${OBJCOPY} -O binary $< $@

%.dfu: %.bin
	$(DFUWRAP) -x -i $< -o $@ -a 0x1800 > /dev/null

TARGETS_ALL = @name@.elf
ifneq ($(DFUWRAP),)
TARGETS_ALL += @name@.dfu
endif

all: $(TARGETS_ALL)

install: $(TARGETS_ALL)
	install -D $(TARGETS_ALL) $(DESTDIR)/

@name@.elf: @name@.o startup_gcc.o

.PHONY: clean

clean:
	@echo -n cleaning up ...
	@rm -fr \
		*.o \
		*.d \
		*.elf \
		*.map \
		.deps \
		autom4te.cache \
		config.log \
		configure
	@echo done

distclean: clean
	@rm -fr \
		Makefile \
		config.status

